/*
// 手动注册的方式
const Router = require('@koa/router')

const userRouter = require('./user')

const router = new Router()

router.get('/', async (ctx) => {
  ctx.body = '首页'
})

router.use(userRouter.routes(), userRouter.allowedMethods())

module.exports = router
*/

const Router = require('@koa/router')
const glob = require('glob')
const { resolve } = require('path')

const router = new Router()

router.get('/', async (ctx) => {
  ctx.body = '首页'
})

glob
  .sync(resolve(__dirname, './', '**/*.js'))
  .filter((value) => value.indexOf('index.js') === -1)
  .map((modulePath) => {
    const moduleRouter = require(modulePath)
    router.use(moduleRouter.routes(), moduleRouter.allowedMethods())
  })

module.exports = router
